package cn.tedu.csmall.product.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;

import java.io.Serializable;

@Component
public class IdUtils {

    @Autowired
    private RedisTemplate<String, Serializable> redisTemplate;

    public synchronized long generateSpuId(){
        ValueOperations<String, Serializable> opsForValue = redisTemplate.opsForValue();
        return opsForValue.increment("spu_id");
    }

    public synchronized long generateSkuId(){
        ValueOperations<String, Serializable> opsForValue = redisTemplate.opsForValue();
        return opsForValue.increment("sku_id");
    }

}
